<template>
	<view class="toudi">
		<view class="title">
			欢迎投递
		</view>
		<view class="hint">
			开发者承诺:(本次用户提交获取的信息将用于纳新，不会对外公开披露您的信息，纳新结束后信息将会被删除)
		</view>

		<view class="basicMessage">
			<view class="basicMessage_title">
				基本信息
			</view>
			<view class="basicMessage_item">
				<u--text type="info" text="姓名:"></u--text><text v-show="warning.nameWarning">姓名不能为空</text>
				<u--input placeholder="请输入姓名" border="surround" type="text" v-model.trim="form.name">
				</u--input>
			</view>
			<view class="basicMessage_item">
				<u--text type="info" text="学号:"></u--text><text v-show="warning.numberWarning">学号格式不对</text>
				<u--input placeholder="请输入学号" border="surround" type="number" v-model.trim="form.number">
				</u--input>
			</view>

			<view class="basicMessage_item">
				<u--text type="info" text="性别:"></u--text>
				<u-radio-group v-model="form.sex">
					<u-radio name="male" label="男"></u-radio>
					<u-radio name="female" label="女"></u-radio>
				</u-radio-group>
			</view>

			<view class="basicMessage_item">
				<u--text type="info" text="邮箱:"></u--text><text v-show="warning.emailWarning">邮箱格式不对</text>
				<u--input placeholder="请输入邮箱" border="surround" type="text" v-model.trim="form.email">
				</u--input>
			</view>

			<view class="basicMessage_item">
				<u--text type="info" text="手机号:"></u--text><text v-show="warning.phoneWarning">手机号格式不对</text>
				<u--input placeholder="请输入手机号" border="surround" type="number" v-model.trim="form.phone">
				</u--input>
			</view>

			<view class="basicMessage_item">
				<u--text type="info" text="平均绩点:"></u--text><text v-show="warning.gradeWarning">平均绩点格式不对</text>
				<u--input placeholder="请输入平均绩点" border="surround" type="text" v-model.trim="form.grade">
				</u--input>
			</view>

			<view class="basicMessage_item">
				<u--text type="info" text="专业班级(格式如:计算机1班):"></u--text><text v-show="warning.classWarning">班级不能为空</text>
				<u--input placeholder="请输入专业班级" border="surround" type="text" v-model.trim="form.class_">
				</u--input>
			</view>

			<view class="basicMessage_item">
				<u--text type="info" text="意向部门:"></u--text>
				<u-radio-group v-model="form.department">
					<u-radio name="exploit" label="开发部"></u-radio>
					<u-radio name="bazaar" label="行政部"></u-radio>
					<u-radio name="administration" label="市场部"></u-radio>
					<u-radio name="manpower" label="人力资源部"></u-radio>
				</u-radio-group>
			</view>

		</view>


		<view class="introduce">
			<view class="introduce_title">
				个人履历(简要说明，每项不得超过140字)
			</view>
			<view class="introduce_item">
				<u--text type="primary" text="个人得奖情况:"></u--text><text
					v-show="warning.rewardsWarning">个人得奖情况不能为空，没有写无</text>
				<u--textarea v-model="form.rewards" placeholder="请输入个人得奖情况" border="bottom" count
					autoHeight></u--textarea>
			</view>
			<view class="introduce_item">
				<u--text type="primary" text="个人介绍(性格,兴趣等等...):"></u--text><text
					v-show="warning.personalDescriptionWarning">个人介绍不能为空</text>
				<u--textarea v-model="form.personalDescription" placeholder="简要介绍一下自己吧" border="bottom" count
					autoHeight></u--textarea>
			</view>

			<view class="introduce_item">
				<u--text type="primary" text="加入启航的原因:"></u--text><text
					v-show="warning.joinReasonWarning">加入原因不能为空</text>
				<u--textarea v-model="form.joinReason" placeholder="你为什么要加入启航,你的初衷是什么?" border="bottom" count
					autoHeight></u--textarea>
			</view>
		</view>

		<u-button type="primary" text="投递" @click="toSubmit()"></u-button>
	</view>
</template>

<script>
	import emailCheck from '../../utils/emailCheck.js'
	import phoneCheck from '../../utils/phoneCheck.js'
	export default {
		data() {
			return {
				form: {
					name: '',
					email: '',
					sex: 'male',
					phone: '',
					grade: '',
					number: '',
					class_: '',
					department: 'exploit',
					rewards: '',
					personalDescription: '',
					joinReason: '',
				},
				warning: {
					joinReasonWarning: false,
					personalDescriptionWarning: false,
					rewardsWarning: false,
					sexWarning: false,
					nameWarning: false,
					emailWarning: false,
					phoneWarning: false,
					gradeWarning: false,
					numberWarning: false,
				}
			}
		},
		methods: {

			toSubmit() {
				const _this = this;
				if (this.form.name == "") {
					this.warning.nameWarning = true;
					return;
				} else {
					this.warning.nameWarning = false;
				}
				try {
					if (this.form.number.length != 10 || this.form.number == "") {
						this.warning.numberWarning = true;
						return;
					} else {
						this.warning.numberWarning = false;
					}
					let number1 = parseFloat(this.form.number);
					if (!number1 instanceof Number) {
						_this.warning.numberWarning = true;
						return;
					}
				} catch (e) {

				}

				if (emailCheck(this.form.email) == false || this.form.email == "") {
					this.warning.emailWarning = true;
					return;
				} else {
					this.warning.emailWarning = false;
				}
				if (phoneCheck(this.form.phone) == false || this.form.phone == "") {
					this.warning.phoneWarning = true;
					return;
				} else {
					this.warning.phoneWarning = false;
				}
				try {
					if (this.form.grade == "") {
						_this.warning.gradeWarning = true;
						return;
					} else {
						let grade1 = parseFloat(_this.form.grade);
						if (isNaN(grade1)) {
							_this.warning.gradeWarning = true;
							return;
						} else {
							if (grade1 > 5.00 || grade1 < 0.00) {
								_this.warning.gradeWarning = true;
								return;
							} else {
								_this.warning.gradeWarning = false;
							}
						}
					}
				} catch (e) {
					_this.warning.gradeWarning = true;
					return;
				}
				if (this.form.class_ == "") {
					this.warning.classWarning = true;
					return;
				} else {
					this.warning.classWarning = false;
				}
				if (this.form.rewards == "") {
					this.warning.rewardsWarning = true;
					return;
				} else {
					this.warning.rewardsWarning = false;
				}
				if (this.form.personalDescription == "") {
					this.warning.personalDescriptionWarning = true;
					return;
				} else {
					this.warning.personalDescriptionWarning = false;
				}
				if (this.form.joinReason == "") {
					this.warning.joinReasonWarning = true;
					return;
				} else {
					this.warning.joinReasonWarning = false;
				}

				console.log(this.form);
				// uni.request({
				// 	header: {
				// 		'Content-Type': 'application/x-www-form-urlencoded'
				// 	},
				// 	url: "https://idctheme.com/api/client/register",
				// 	method: 'POST',
				// 	dataType: 'json',
				// 	data: {
				// 		firstname: _this.register.firstname,
				// 		lastname: _this.register.lastname,
				// 		email: _this.register.email,
				// 		phone: _this.register.phone,
				// 		password: _this.register.password,

				// 	},
				// 	success: res => {
				// 		if (res.data.status == "error") {
				// 			uni.showToast({
				// 				title: "注册失败",
				// 				duration: 2000,
				// 				mask: true
				// 			})

				// 		} else {
				// 			uni.showToast({
				// 				title: "注册成功",
				// 				duration: 5000,
				// 				mask: true
				// 			})
				// 			uni.switchTab({
				// 				url: '/pages/users/users'
				// 			})

				// 		}
				// 	},
				// 	fail: err => {
				// 		uni.showToast({
				// 			title: "请稍后再试",
				// 			duration: 2000,
				// 			mask: true
				// 		})
				// 	}
				// })
			},
		}
	}
</script>

<style>
	.toudi {
		width: 90%;
		height: 3000rpx;
		margin: 0 auto;
		background-color: #f9f9f9;
	}

	.title {
		font-size: 42rpx;
		font-weight: 700;
		text-align: center;
	}

	.hint {
		margin-top: 20rpx;
		font-size: 20rpx;
		font-family: "黑体";
		color: #b5bac3;
	}

	.basicMessage,
	.introduce {
		margin-top: 20rpx;
		width: 100%;
		border: 1px solid #e4e7ec;
	}

	.basicMessage_item,
	.introduce_item {
		padding: 15rpx;
	}

	.basicMessage_title,
	.introduce_title {
		font-size: 35rpx;
		font-weight: 700;
	}

	.basicMessage_item,
	.introduce_item {

		font-weight: 500;
	}

	.basicMessage text,
	.introduce text {
		font-size: 20rpx;
		color: red;

	}
</style>